﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using QUT.Bio.Util;

namespace BlastExplorer.SilverMapDataProducer {
	/// <summary>
	/// Introduce an extended Xref class with ability to support selection
	/// plus additional information.
	/// </summary>

	public class Xref: QUT.Bio.Util.Xref, INotifyPropertyChanged {
		public Xref (
			string database,
			string id,
			string description,
			string organism
		)
			: base( database, id ) {
			this.description = description;
			this.organism = organism;
		}

		private string description;
		private string organism;
		private bool selected;

		[Displayed]
		public bool Selected {
			get {
				return selected;
			}

			set {
				if ( value != selected ) {
					selected = value;

					if ( PropertyChanged != null ) {
						PropertyChanged( this, new PropertyChangedEventArgs( "Selected" ) );
					}
				}
			}
		}

		public event PropertyChangedEventHandler  PropertyChanged;

		[Displayed]
		public string Description {
			get {
				return description;
			}
		}

		[Displayed]
		public string Organism {
			get {
				return organism;
			}
		}

		public XElement ToXml () {
			return new XElement( "Xref",
				new XElement( "Database", Database ),
				new XElement( "Id", Id ),
				new XElement( "Description", description ),
				new XElement( "Organism", organism )
			);
		}

		public static Xref FromXml ( XElement element ) {
			return new Xref(
				element.Element("Database").Value,
				element.Element("Id").Value,
				element.Element("Description").Value,
				element.Element("Organism").Value
			);
		}
	}
}
